<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Admin\Controller\AdminController;

class RoleController extends AdminController {

    function _initialize() {
        parent::_initialize();
        $this->assign('action', 'role');
        $this->assign('sys', 'dashboard'); // 数据集
    }
    
    //管理员列表
    public function index() {
        $cateModel = M('role');
        $list = $cateModel->select();
        $this->assign('list', $list);
        $this->display();
    }

    //添加管理员
    public function add() {
        if (IS_POST) {
            $date = $_POST;
            $re = M('role')->add($date);
            if ($re) {
                $this->success("组添加成功！", U('index'));
            } else {
                $this->error("添加组出错");
            }
        }
        $this->display();
    }

    //修改管理员
    function edit() {
        $id = I('id');
        $uModel = M('role');
        if (empty($id) | $id <= 0) {
            $this->error('非法的操作', U('Group'));
        }

        if (IS_POST) {
            $id = $_GET['id'];
            $date = $_POST;
            $resule = $uModel->where('id=%d', $id)->save($_POST);
            if (false !== $resule) {
                //记录操作日志

                $this->success('修改成功！正在跳转……', U('index'));
            } else {
                $this->error('修改失败~~~ 正在返回……');
            }
        }
        
        $date = $uModel->where('id=%d', $id)->find();
        $this->assign('date', $date);
        $this->display();
    }

    function del() {

        $id = I('post.data');
        $uModel = M('role');
        $name = $uModel->where('id=%d', $id)->getField('name');
        if ($uModel->where('id=%d', $id)->delete()) {
            //记录操作日志

            $this->success('删除成功！正在跳转……');
        } else {
            $this->error('删除失败！正在返回……');
        }
    }


}
